import { BaseCommand, TSelectRanage, TMergeCell } from '../types/common.interface';
import { RenderTrigger } from '../cors/render-trigger';
import { Config } from '../cors/config';

export class FreezeCommand extends BaseCommand {
    protected lastPosition: number = -1;
    constructor(
        protected conf: Config,
        protected render: RenderTrigger,
        protected position: number,
        protected type: 'row'|'col'
    ) {
        super();
    }
    public execute(): boolean {
        if(this.type === 'row') {
            this.lastPosition = this.conf.freeze.row;
            this.conf.updateFreezeRow(this.position);
            this.render.triggerRenderAll();
            return true;
        }
        if(this.type === 'col') {
            this.lastPosition = this.conf.freeze.col;
            this.conf.updateFreezeCol(this.position);
            this.render.triggerRenderAll();
        }
        return false;
    }
    public redo(): boolean {
        if(this.type === 'row') {
            this.conf.updateFreezeRow(this.lastPosition);
            this.render.triggerRenderAll();
            return true;
        }
        if(this.type === 'col') {
            this.conf.updateFreezeCol(this.lastPosition);
            this.render.triggerRenderAll();
            return true;
        }
        return false;
    }
} 